package com.zscat.mallplus.qsg.impl;

import com.zscat.mallplus.ums.service.RedisService;
import com.zscat.mallplus.utils.WXSubscribeMsgUtil;
import org.apache.commons.lang.StringUtils;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.quartz.QuartzJobBean;

import javax.annotation.Resource;


public class WeixinTokenTask extends QuartzJobBean {

    @Value("${wxpay.appId}")
    private String wxH5Appid;

    @Value("${wxpay.appSecret}")
    private String wxH5Secret;

    @Resource
    private RedisService redisService;

    @Override
    protected void executeInternal(JobExecutionContext context){
        try {
            WXSubscribeMsgUtil wxutil = WXSubscribeMsgUtil.getInstance();
            String accessToken = wxutil.getAccessToken(wxH5Appid,wxH5Secret);
            if(StringUtils.isNotBlank(accessToken)){
                redisService.set("wx_accesstoken",accessToken);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
